import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    redirect:"/home"
  },
  {
    path: '/',
    component: () => import('../views/Layout.vue'),
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('../views/home/Home.vue'),
        children: [
          {
            path: 'detail',
            component: () => import('@/pages/detail/Detail.vue')
          },
          {
            path: 'list',
            component: () => import('@/pages/list/List.vue')
          },
          {
            path: 'banner',
            component: () => import('@/pages/banner/Banner.vue')
          },
          {
            path : 'common',
            component: () => import('@/pages/more/common.vue')
          },
          {
            path : '1',
            component: () => import('@/pages/more/home1.vue'),
            beforeEnter(to,from,next){
              // console.log(localStorage.getItem('token_user'))
              if(localStorage.getItem('token_user') == null){
                next({path:"/login"});
              }else{
                next();
              }
            }
          },
          {
            path : '2',
            component: () => import('@/pages/more/home2.vue'),
            beforeEnter(to,from,next){
              // console.log(localStorage.getItem('token_user'))
              if(localStorage.getItem('token_user') == null){
                next({path:"/login"});
              }else{
                next();
              }
            }
          },
          {
            path : '3',
            component: () => import('@/pages/more/home3.vue'),
            beforeEnter(to,from,next){
              // console.log(localStorage.getItem('token_user'))
              if(localStorage.getItem('token_user') == null){
                next({path:"/login"});
              }else{
                next();
              }
            }
          },
          {
            path : '4',
            component: () => import('@/pages/more/home4.vue'),
            beforeEnter(to,from,next){
              // console.log(localStorage.getItem('token_user'))
              if(localStorage.getItem('token_user') == null){
                next({path:"/login"});
              }else{
                next();
              }
            }
          },
          {
            path : '5',
            component: () => import('@/pages/more/home5.vue'),
            beforeEnter(to,from,next){
              // console.log(localStorage.getItem('token_user'))
              if(localStorage.getItem('token_user') == null){
                next({path:"/login"});
              }else{
                next();
              }
            }
          },
          {
            path : '6',
            component: () => import('@/pages/more/home6.vue'),
            beforeEnter(to,from,next){
              // console.log(localStorage.getItem('token_user'))
              if(localStorage.getItem('token_user') == null){
                next({path:"/login"});
              }else{
                next();
              }
            }
          },
          {
            path : '7',
            component: () => import('@/pages/more/home7.vue'),
            beforeEnter(to,from,next){
              // console.log(localStorage.getItem('token_user'))
              if(localStorage.getItem('token_user') == null){
                next({path:"/login"});
              }else{
                next();
              }
            }
          },
        ]
      },
      {
        path: 'about',
        name: 'About',
        component: () => import('../views/about/About.vue')
      },
      {
        path: 'classify',
        name: 'Classify',
        component: () => import('../views/classify/Classify.vue'),
        children: [
          {
            path: 'classify0',
            component: () => import('../views/classify/Classify.vue')
          },
          {
            path: 'classify1',
            component: () => import('../views/classify/Classify.vue')
          },
          {
            path: 'classify2',
            component: () => import('../views/classify/Classify.vue')
          },
          {
            path: 'classify3',
            component: () => import('../views/classify/Classify.vue')
          },
          {
            path: 'classify4',
            component: () => import('../views/classify/Classify.vue')
          },
          {
            path: 'classify5',
            component: () => import('../views/classify/Classify.vue')
          },
        ]
      },
      {
        path: 'cart',
        name: 'Cart',
        component: () => import('../views/cart/Cart.vue'),
        beforeEnter(to,from,next){
          // console.log(localStorage.getItem('token_user'))
          if(localStorage.getItem('token_user') == null){
            next({path:"/login"});
          }else{
            next();
          }
        }
      },
      {
        path: 'personal',
        name: 'Personal',
        component: () => import('../views/personal/Personal.vue'),
        beforeEnter(to,from,next){
          // console.log(localStorage.getItem('token_user'))
          if(localStorage.getItem('token_user') == null){
            next({path:"/login"});
          }else{
            next();
          }
        },
        children:[
          {
            path : 'order',
            name : 'Order',
            component : () => import('@/pages/order/order.vue'),
            beforeEnter(to,from,next){
              // console.log(localStorage.getItem('token_user'))
              if(localStorage.getItem('token_user') == null){
                next({path:"/login"});
              }else{
                next();
              }
            }
          }
        ]
      },
    ]
  },
  {
    path: '/login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/register',
    component: () => import('../views/Register.vue')
  },
  {
    path: '/search',
    component: () => import('../views/Search.vue')
  },
  {
    path: '/classifySearch',
    component: () => import('../views/ClassifySearch.vue')
  },
  {
    path : '/address',
    component: () => import('../views/address.vue'),
    beforeEnter(to,from,next){
      // console.log(localStorage.getItem('token_user'))
      if(localStorage.getItem('token_user') == null){
        next({path:"/login"});
      }else{
        next();
      }
    }
  },
  {
    path : '/history',
    component: () => import('@/pages/more/history.vue'),
    beforeEnter(to,from,next){
      // console.log(localStorage.getItem('token_user'))
      if(localStorage.getItem('token_user') == null){
        next({path:"/login"});
      }else{
        next();
      }
    }
  }

]

const router = new VueRouter({
  routes
})

export default router
